#include "myform.h"
#include "ui_myform.h"
#include<QDebug>

///////////////////////////////////////////////////////
//左侧界面中的按钮样式(在线音乐和我的音乐)///////////////////
//////////////////////////////////////////////////////

myForm::myForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::myForm)
{
    ui->setupUi(this);
    InitUI();
}

myForm::~myForm()
{
    delete ui;
}

//提供设置图标和文本的方法
void myForm::setIconAndText(const QString &myIcon, const QString &content, int pageId)
{
    ui->myIcon->setPixmap(QPixmap(myIcon));
    ui->myText->setText(content);
    this->pageId=pageId;
}

//提供pageId的接口函数
int myForm::getPageId()
{
    return this->pageId;
}

//清除背景色
void myForm::clearBackground()
{
    ui->myStyle->setStyleSheet("#myStyle:hover{background:#D8D8D8;}");
}

//初始化动画效果
void myForm::InitUI()
{
    ui->lineBox->hide();
    // 设置line1的动画效果
    animation1=new QPropertyAnimation(ui->line1,"geometry",this);
    animation1->setDuration(1500);
    animation1->setKeyValueAt(0,QRect(0,20,2,0));
    animation1->setKeyValueAt(0.5,QRect(0,0,2,20));
    animation1->setKeyValueAt(1,QRect(0,20,2,0));
    animation1->setLoopCount(-1);
    animation1->start();
    // 设置line2的动画效果
    animation2=new QPropertyAnimation(ui->line2,"geometry",this);
    animation2->setDuration(1600);
    animation2->setKeyValueAt(0,QRect(7,20,2,0));
    animation2->setKeyValueAt(0.5,QRect(7,0,2,20));
    animation2->setKeyValueAt(1,QRect(7,20,2,0));
    animation2->setLoopCount(-1);
    animation2->start();
    // 设置line3的动画效果
    animation3=new QPropertyAnimation(ui->line3,"geometry",this);
    animation3->setDuration(1700);
    animation3->setKeyValueAt(0,QRect(14,20,2,0));
    animation3->setKeyValueAt(0.5,QRect(14,0,2,20));
    animation3->setKeyValueAt(1,QRect(14,20,2,0));
    animation3->setLoopCount(-1);
    animation3->start();
    // 设置line4的动画效果
    animation4=new QPropertyAnimation(ui->line4,"geometry",this);
    animation4->setDuration(1800);
    animation4->setKeyValueAt(0,QRect(21,20,2,0));
    animation4->setKeyValueAt(0.5,QRect(21,0,2,20));
    animation4->setKeyValueAt(1,QRect(21,20,2,0));
    animation4->setLoopCount(-1);
    animation4->start();
}

//显示或隐藏动画效果
void myForm::showAnimal(bool isShow)
{
    if(isShow)
    {
        ui->lineBox->show();
    }
    else
    {
        ui->lineBox->hide();
    }
}

//重写鼠标按下事件
void myForm::mousePressEvent(QMouseEvent *event)
{
    (void)event;
    //鼠标按下背景变为绿色
    ui->myStyle->setStyleSheet("#myStyle{background-color:rgb(30,206,154);}");
    qDebug()<<this->pageId;
    emit myClick(this->pageId);//将pageId发送出去
}
